package com.ln.asset.core.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ln.asset.common.result.R;
import com.ln.asset.common.result.ResponseEnum;
import com.ln.asset.core.pojo.BorrowRecipients;
import com.ln.asset.core.service.BorrowRecipientsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 资产领用记录表 前端控制器
 * </p>
 *
 * @author wuwenzhe
 * @since 2022-04-27
 */
@Api(tags = "资产借款申请")
@RestController
@RequestMapping("/admin/borrowRecipients")
@CrossOrigin
public class BorrowRecipientsController {

    //引入service
    @Resource
    private BorrowRecipientsService borrowRecipientsService;

    //全查分页
    @GetMapping
    public R getAll(){
        List<BorrowRecipients> list = borrowRecipientsService.list();
        return R.ok().data("list",list);
    }
    @ApiOperation("获取借款人分页列表")
    @PostMapping("/list/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(value = "每页记录数", required = true)
            @PathVariable Long limit){

        Page<BorrowRecipients> pageParam = new Page<>(page, limit);
        IPage<BorrowRecipients> pageModel = borrowRecipientsService.page(pageParam);
        return R.ok().data("pageModel", pageModel);
    }

    @ApiOperation("新增积分等级")
    @PostMapping("/save")
    public R save(
            @ApiParam(value = "积分等级对象", required = true)
            @RequestBody BorrowRecipients borrowRecipients){
        boolean result = borrowRecipientsService.save(borrowRecipients);
        if (result) {
            return R.ok().message("保存成功");
        } else {
            return R.error().message("保存失败");
        }
    }
    //根据id查看
    //详情页面的接口
    @ApiOperation("获取借款人信息")
    @GetMapping("/show/{id}")
    public R show(
            @ApiParam(value = "借款人id", required = true)
            @PathVariable Integer id) {
        BorrowRecipients byId = borrowRecipientsService.getById(id);
        return R.ok().data("borrowerDetailVO", byId);
    }

}

